package com.rany.day09.demo03;

import java.util.HashMap;
import java.util.Iterator;

public class Test {
    public static void main(String[] args) {
        demo01();
        demo02();
    }

    private static void demo02() {
        HashMap<Person,String> hashMap = new HashMap<>();
        hashMap.put(new Person("lin",25),"nanjing");
        hashMap.put(new Person("lin",25),"shanghai");
        hashMap.put(new Person("lin",26),"nanjing");
        hashMap.put(new Person("lu",25),"nanjing");

        Iterator<Person> iterator = hashMap.keySet().iterator();
        while (iterator.hasNext()){
            Person next = iterator.next();
            String s = hashMap.get(next);
            System.out.println(s+"#"+next);
        }
    }

    private static void demo01() {
        HashMap<String,Person> hashMap = new HashMap<>();
        hashMap.put("南京",new Person("lu",25));
        hashMap.put("冰岛",new Person("gu",27));
        hashMap.put("琉球",new Person("lin",26));

        for (String key : hashMap.keySet()) {
            Person person = hashMap.get(key);
            System.out.println(person);
        }
    }
}
